////////
//  Making a plugin :: Example
////////
--[[
A plugin works this way :
- When Inscript is being loaded, it will inspect every file
  in this folder that ends with "_plugin.lua" .
- For each file, it will gather data. Let's swipe through them :
]]--

-- The first bit of data is the raw name of your plugin.
-- It is what is before your "_plugin.lua" filename.
-- Console commands are based on it.

PLUGIN.Name = "Stuff maker"		-- The friendly Display name of your plugin.
PLUGIN.DefaultOn = false			-- Should it enable it the first time GMod ever finds your Plugin ?
PLUGIN.Description = "Does stuff."	-- Description displayed in the plugin menu.
PLUGIN.Trigger = false				-- If set to true, it means you are making a Perform Plugin (see below).

//// PLUGIN:LoadParameters()
// This function is triggered only once while Inscripts is being loaded.
// It is also triggered when you reload the plugin list.
// It allows you to generate custom parameters the end user can set up.

function PLUGIN:LoadParameters()
	-- The usual Checkbox.
	-- It is stored as a number (0 / 1).
	
	self:AddParameter("arrange", 	{ Type = "checkbox", Defaults = "0", Text = "Arrange stuff constantly" } )
	
	-- A simple label. This does not generate convars.
	self:AddParameter("name_label", { Type = "label", Text = "Stuff name :" } )
	
	-- A text entry. Note that the Defaults is set only if the convar didn't exist before.
	-- That means, the default value will persist even if the player's nick has changed.
	-- Be careful about that, every convar is persistant.
	-- It is stored as a string.
	self:AddParameter("name", 		{ Type = "textentry", Defaults = (LocalPlayer():Nick() or "Someone") .. "'s Stuff" } )
	
	-- A slider. Note that the internal fonction does NOT provide boundary check or clamping.
	-- It is stored as a number.
	self:AddParameter("max", 		{ Type = "slider", Defaults = "30", Min = "1", Max = "60", Decimals = "0", Text = "Maximum stuff allowed." } )
	
	-- Adds a button. It does not generate any console commands nor convars.
	-- You can NOT execute the button function if the plugin is not mounted.
	self:AddParameter("doarrange", 		{ Type = "button", Text = "Rearrange Stuff now", DoClick = function() self:_Rearrange() end } )
end

//// PLUGIN:Load()
// This function is triggered when the plugin is mounted.
// So this is also executed if (Inscripts has Auto-mount enabled) and (this is checked).
// If the plugin is a Perform Plugin, there is no "Unmount".
// That means a Perform Plugin just does an action when pressing the Perform button, which is this function.
// A Perform Plugin can also be Auto-mounted.
function PLUGIN:Load()
	-- Here you see how GetString and GetNumber can be used to find out the parameters.
	-- We are using the AddParameter first argument as the argument to gather our convar back.
	RunConsoleCommand("say", self:GetString("name") .. " is being loaded ! I have set up a maximum of ".. self:GetNumber("max") .." stuff !")
end

//// PLUGIN:Unload()
// Unload is NEVER triggered on a Perform-type plugin.
function PLUGIN:Unload()
	RunConsoleCommand("say", "I'm unloading " .. self:GetString("name") .. " !")
end

//// PLUGIN::NOT_A_HOOK
// A function is NEVER automatically hooked.
function PLUGIN:Rearrange()
	print("Rearranging my stuff...")
end

//// PLUGIN::HOOK
// A function that is registered under PLUGIN.HOOK Subtable will be automatically hooked when the plugin is mounted,
// and automatically unhooked when the plugin is unmounted.
// Note that a Perform Plugin NEVER use hooks nor does it hook them if there exists.
function PLUGIN.HOOK:Think()
	-- Here you see how checkboxes convars can be handled.
	if self:GetNumber("arrange") > 0 then
		self:_Rearrange()
	end
end
